package org.example.serviceoffice.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.model.manage.bean.po.Student;
import org.example.serviceoffice.mapper.StudentMapper;
import org.example.serviceoffice.service.OfficeStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 办公室学生服务实现类
 */
@Service
public class OfficeStudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements OfficeStudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student addStudent(Student student) {
        if (student == null) {
            throw new IllegalArgumentException("学生信息不能为空");
        }

        // 使用studentMapper添加学生
        studentMapper.insert(student);
        return student;
    }

    @Override
    public boolean updateReportStatus(Integer studentId, Integer reportCheck) {
        if (studentId == null || reportCheck == null) {
            throw new IllegalArgumentException("学生ID和报到状态不能为空");
        }

        // 更新学生报到状态
        UpdateWrapper<Student> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", studentId)
                     .set("report_check", reportCheck);

        return studentMapper.update(null, updateWrapper) > 0;
    }
}